/*
 *    Copyright (c) 2018-2025, nart All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * Redistributions of source code must retain the above copyright notice,
 * this list of conditions and the following disclaimer.
 * Redistributions in binary form must reproduce the above copyright
 * notice, this list of conditions and the following disclaimer in the
 * documentation and/or other materials provided with the distribution.
 * Neither the name of the pig4cloud.com developer nor the names of its
 * contributors may be used to endorse or promote products derived from
 * this software without specific prior written permission.
 * Author: nart
 */

package com.nai365.nart.ware.mapper;

import com.nai365.nart.common.data.datascope.NartBaseMapper;
import com.nai365.nart.ware.entity.WareSku;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

import java.util.List;
import java.util.Set;

/**
 * 商品库存
 *
 * @author baogs
 * @date 2022-07-02 13:21:19
 */
@Mapper
public interface WareSkuMapper extends NartBaseMapper<WareSku> {

	/**
	 * 采购成功，商品入库
	 */
	void addStock(@Param("skuId") Long skuId, @Param("ownerId") Long ownerId, @Param("skuNum") Integer skuNum);

	/**
	 * 查询sku是否有库存
	 */
	Long getSkusStock(Long skuId);

	/**
	 * 查询商品库存充足的仓库
	 * @param skuIds 商品项ID集合
	 * @return
	 */
	List<WareSku> selectListHasSkuStock(@Param("skuIds") Set<Long> skuIds);

	/**
	 * 锁定库存
	 * @param skuId 商品项ID
	 * @param ownerId 仓库ID
	 * @param count 待锁定库存数
	 * @return 1成功  0失败
	 */
	Long lockSkuStock(@Param("skuId") Long skuId, @Param("ownerId") Long ownerId, @Param("count") Integer count);

	/**
	 * 解锁库存
	 * @param skuId
	 * @param ownerId
	 * @param num
	 * @param taskDetailId
	 */
	void unLockStock(@Param("skuId") Long skuId, @Param("ownerId") Long ownerId, @Param("count") Integer count);
}
